using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;
using SCS.Common.Models;
namespace SCS.DAL.Mapping
{
    public class MembershipRoleMap : EntityTypeConfiguration<MembershipRole>
    {
        public MembershipRoleMap()
        {
            // Primary Key
            this.HasKey(t => t.roleID);

            // Properties
            this.Property(t => t.roleID)
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);

            this.Property(t => t.roleName)
                .IsRequired()
                .HasMaxLength(256);

            // Table & Column Mappings
            this.ToTable("MembershipRole");
            this.Property(t => t.roleID).HasColumnName("roleID");
            this.Property(t => t.roleName).HasColumnName("roleName");

            // Relationships
            this.HasMany(t => t.MembershipUsers)
                .WithMany(t => t.MembershipRoles)
                .Map(m =>
                {
                    m.ToTable("MembershipUsersInRoles");
                    m.MapLeftKey("roleID");
                    m.MapRightKey("userID");
                });


        }
    }
}
